<?php
	class diemhkdb
	{
		public function Add($MaHocSinh, $MaMonHoc, $KiemTra_Mot, $KiemTra_Hai, $KiemTra_Ba, $DTB_HK, $HocKy, $NamHoc, $ThiLai)
		{
			$sql = "INSERT INTO  `tbl_diemhk` (`MaHocSinh`, `MaMonHoc`, `KiemTra_Mot`, `KiemTra_Hai`, `KiemTra_Ba`, `DTB_HK`, `HocKy`, `NamHoc`, `ThiLai`) 
			VALUES ('$MaHocSinh', $MaMonHoc, $KiemTra_Mot, $KiemTra_Hai, $KiemTra_Ba, $DTB_HK, '$HocKy', '$NamHoc', $ThiLai)";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Delete($MaHocSinh,$MaMonHoc,$HocKy,$NamHoc)
		{
			$sql = " DELETE FROM  `tbl_diemhk`  WHERE MaHocSinh = '$MaHocSinh' AND MaMonHoc = $MaMonHoc AND HocKy = '$HocKy' AND NamHoc = '$NamHoc' ";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Update($MaHocSinh, $MaMonHoc, $KiemTra_Mot, $KiemTra_Hai, $KiemTra_Ba, $DTB_HK, $HocKy, $NamHoc, $ThiLai)
		{
			$sql = "UPDATE  `tbl_diemhk` 
			 SET KiemTra_Mot = '$KiemTra_Mot',
				 KiemTra_Hai = '$KiemTra_Hai',
				 KiemTra_Ba = '$KiemTra_Ba',
				 DTB_HK = '$DTB_HK',
				 ThiLai = $ThiLai
			
			WHERE MaHocSinh = '$MaHocSinh' AND MaMonHoc = $MaMonHoc AND HocKy = '$HocKy' AND NamHoc = '$NamHoc'  "; 
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
	
	
		public function GetList($MaHocSinh, $MaMonHoc, $KiemTra_Mot, $KiemTra_Hai, $KiemTra_Ba, $DTB_HK, $HocKy, $NamHoc)
		{
			$sql = " SELECT * FROM  `tbl_diemhk`,`tbl_hocsinh`,`tbl_monhoc`, `tbl_namhoc`, `tbl_lop`,`tbl_hocsinh_lop`,`tbl_phanlop` WHERE  tbl_diemhk.MaHocSinh = tbl_hocsinh.MaHocSinh AND tbl_diemhk.MaMonHoc = tbl_monhoc.MaMonHoc AND tbl_diemhk.NamHoc = tbl_namhoc.NamHoc AND tbl_diemhk.HocKy=tbl_namhoc.HocKy AND tbl_lop.MaLop = tbl_phanlop.MaLop AND tbl_phanlop.MaPhanLop = tbl_hocsinh_lop.MaPhanLop AND tbl_hocsinh.MaHocSinh = tbl_hocsinh_lop.MaHocSinh ";
			if($MaHocSinh!="")
				$sql .= " AND tbl_diemhk.MaHocSinh = '$MaHocSinh' ";
			if($MaMonHoc!="")
				$sql .= " AND tbl_diemhk.MaMonHoc = $MaMonHoc ";
			if($KiemTra_Mot!="")
				$sql .= " AND tbl_diemhk.KiemTra_Mot = $KiemTra_Mot ";
			if($KiemTra_Ba!="")
				$sql .= " AND tbl_diemhk.KiemTra_Ba = $KiemTra_Ba ";
			if($DTB_HK!="")
				$sql .= " AND tbl_diemhk.DTB_HK = $DTB_HK ";
			if($HocKy!="")
				$sql .= " AND tbl_diemhk.HocKy = '$HocKy' ";
			if($NamHoc!="")
				$sql .= " AND tbl_diemhk.NamHoc = '$NamHoc' ";	
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		public function Find($TenHocSinh, $TenMonHoc, $KiemTra_Mot, $KiemTra_Hai, $KiemTra_Ba, $DTB_HK, $HocKy,
		 $NamHoc)
		
		{
			$sql = "  SELECT * FROM  `tbl_diemhk`,`tbl_hocsinh`,`tbl_monhoc`, `tbl_namhoc`, `tbl_lop`,`tbl_hocsinh_lop`,`tbl_phanlop` WHERE  tbl_diemhk.MaHocSinh = tbl_hocsinh.MaHocSinh AND tbl_diemhk.MaMonHoc = tbl_monhoc.MaMonHoc AND tbl_diemhk.NamHoc = tbl_namhoc.NamHoc AND tbl_diemhk.HocKy=tbl_namhoc.HocKy AND tbl_lop.MaLop = tbl_phanlop.MaLop AND tbl_phanlop.MaPhanLop = tbl_hocsinh_lop.MaPhanLop AND tbl_hocsinh.MaHocSinh = tbl_hocsinh_lop.MaHocSinh ";
			if($MaHocSinh!="")
				$sql .= " AND tbl_diemhk.TenHocSinh LIKE '%$TenHocSinh%' ";
			if($MaMonHoc!="")
				$sql .= " AND tbl_diemhk.TenMonHoc LIKE '%$TenMonHoc%' ";
			if($KiemTra_Mot!="")
				$sql .= " AND tbl_diemhk.KiemTra_Mot = $KiemTra_Mot ";
			if($KiemTra_Hai!="")
				$sql .= " AND tbl_diemhk.KiemTra_Hai = $KiemTra_Hai ";
			if($KiemTra_Ba!="")
				$sql .= " AND tbl_diemhk.KiemTra_Ba = $KiemTra_Ba ";
			if($DTB_HK!="")
				$sql .= " AND tbl_diemhk.DTB_HK = $DTB_HK ";
			if($HocKy!="")
				$sql .= " AND tbl_diemhk.HocKy = $HocKy ";
			if($NamHoc!="")
				$sql .= " AND tbl_diemhk.NamHoc = '$NamHoc' ";	
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}		
	}
?>